|
|
Component
AsynchroSlave
Asynchronous serial communication - slave
Component Level: High
Category:
CPU Internal Peripherals-Communication
Typical Usage:
(Examples of a typical usage of the component in user code.
For more information please
see the page Component Code
Typical Usage.)
Required component name is "ASL1". There are the following three typical usage modes:
(1)
MAIN.C
byte ch;
byte err;
ASL1_TError error;
void main(void)
{
for(;;) {
//Wait for a character.
//The slave must be selected by a master first.
while(ASL1_GetCharsInRxBuf() == 0);
//Read received character and send it if the slave is selected
//and no error is detected
if( ASL1_RecvChar(&ch) == ERR_OK) {
ASL1_SendChar(ch);
} else {
// The GetBreak method must be used first because
// the GetError method clear the break flag
// This method is available if the Break
// signal is enabled (Advanced view).
ASL1_GetBreak(&b);
if (b) {
// the break character was received
}
ASL1_GetError(&error)
if(error.errName.Parity)
//Parity error
else if(error.errName.Framing)
//Framing error
.
.
.
}
}
}
(2)
EVENTS.C
void ASL1_OnRxChar(void)
{
byte ch;
//Read received character and if no error is detected
if(ASL1_RecvChar(&ch) == ERR_OK)
ASL1_SendChar(ch); //send it back
}
(3)
MAIN.C
byte ch;
ASL1_TError error; //TError union is defined in the header file
void main(void)
{
while(ASL1_GetCharsInRxBuf() == 0); //Wait for a character
ASL1_RecvChar(&ch); //Read received character
//Read the last communication errors
ASL1_GetError(&error)
if(error.err == 0) {
//Send the last received character if no error is detected
ASL1_SendChar(ch);
} else {
if(error.errName.Parity) {
//Parity error
} else if(error.errName.Framing) {
//Framing error
}
.
.
}
.
.
}
|